package model

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Course struct {
	Id          uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	UserId      uint           `gorm:"column:user_id;type:bigint(20);comment:教练ID;not null;" json:"user_id"`               // 教练ID
	Describe    string         `gorm:"column:describe;type:varchar(255);comment:课程简介;not null;" json:"describe"`           // 课程简介
	CoursePrice float64        `gorm:"column:course_price;type:decimal(10, 2);comment:课程价格;not null;" json:"course_price"` // 课程价格
	CourseUrl   string         `gorm:"column:course_url;type:varchar(255);comment:课程图片;not null;" json:"course_url"`       // 课程图片
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (c *Course) TableName() string {
	return "course"
}
func (c *Course) CreateCourse() error { //创建课程
	return config.DB.Create(&c).Error
}
